package com.example.springboot.controller;


import com.example.springboot.common.Result;
import com.example.springboot.controller.request.PaperPageRequest;
import com.example.springboot.entity.Paper;
import com.example.springboot.service.IPaperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;


@CrossOrigin
@RestController
@RequestMapping("/paper")
public class PaperController {

    @Autowired
    IPaperService paperService;

    @PostMapping("/save")
    public Result save(@RequestBody Paper obj) {
        paperService.save(obj);
        return Result.success();
    }

    @PutMapping("/update")
    public Result update(@RequestBody Paper obj) {
        paperService.update(obj);
        return Result.success();
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id) {
        paperService.deleteById(id);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id) {
        Paper obj = paperService.getById(id);
        return Result.success(obj);
    }

    @GetMapping("/list")
    public Result list() {
        List<Paper> list = paperService.list();
        return Result.success(list);
    }





    @GetMapping("/page")
    public Result page(PaperPageRequest pageRequest) {
        return Result.success(paperService.page(pageRequest));
    }

}